﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data.SqlClient;

namespace DAO
{
    public class Email_KhuyenMai_DAO
    {
        BanHang_LinQDataContext db = new BanHang_LinQDataContext();
        List<Email_KhuyenMai> listds = new List<Email_KhuyenMai>();

        // 1.phương thức lấy tất cả email khuyến mãi
        public List<Email_KhuyenMai> LayDanhSach_Email()
        {
            List<Email_KhuyenMai> email = db.Email_KhuyenMais.Where(e => e.isDelete == 0).ToList();
            return email;
        }

        //2.phương thức lấy thông tin email
        public Email_KhuyenMai LayThongTin_EMailKhuyenMai(Email_KhuyenMai email)
        {
            Email_KhuyenMai kq = db.Email_KhuyenMais.SingleOrDefault(h => h.Email == email.Email && h.isDelete == 0);
            return kq;
        }

        // 3.phương thức thêm email
        public bool Them_Email(Email_KhuyenMai email)
        {
            try
            {
                db.Email_KhuyenMais.InsertOnSubmit(email);
                db.SubmitChanges();
                return true;
            }
            catch (SqlException ex)
            {
                throw ex;
                return false;
            }
        }

        // 4.phương thức xóa email
        public bool Xoa_Email(Email_KhuyenMai email)
        {
            try
            {
                Email_KhuyenMai kq = db.Email_KhuyenMais.SingleOrDefault(h => h.Email == email.Email);
                email.isDelete = 0;
                db.SubmitChanges();
                return true;
            }
            catch (SqlException ex)
            {
                throw ex;
                return false;
            }
        }

        // 5.phương thức sửa email
        public bool Sua_Email(Email_KhuyenMai email)
        {
            try
            {
                Email_KhuyenMai kq = db.Email_KhuyenMais.SingleOrDefault(h => h.Email == email.Email);
                db.SubmitChanges();
                return true;
            }
            catch (SqlException ex)
            {
                throw ex;
                return false;
            }
        }
    }
}
